﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping;
using Konekcija.Core.Reporting.Dto.Application.Configurations;

namespace Konekcija.Core.Reporting.Mappings.Configurations
{
    public class WebsiteMap : ClassMap<Website>
    {
        public WebsiteMap()
        {
            Schema("config");
            Table("Websites");

            Id(x => x.Id).GeneratedBy.GuidComb().Not.Nullable();
            Map(x => x.Name).Nullable();
            Map(x => x.Url).Nullable();
            Map(x => x.Logo).Nullable();
            Map(x => x.Css).Nullable();
            Map(x => x.Def).Nullable();
            Map(x => x.DateCreated).Nullable();

            HasManyToMany(x => x.CategorySets)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Cascade.None()
                .ParentKeyColumn("WebsiteId")
                .ChildKeyColumn("CategorySetId")
                .Table("config.CategorySetsToWebsites");

            HasManyToMany(x => x.NavigationSets)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Cascade.None()
                .ParentKeyColumn("WebsiteId")
                .ChildKeyColumn("NavigationSetId")
                .Table("config.NavigationSetsToWebsites");

            HasMany(x => x.Regions)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("WebsiteId")
                .Cascade.None();

            HasManyToMany(x => x.Languages)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Cascade.None()
                .ParentKeyColumn("WebsiteId")
                .ChildKeyColumn("LanguageId")
                .Table("config.LanguagesToWebsites");

            HasManyToMany(x => x.WebsiteCurrencies)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Cascade.None()
                .ParentKeyColumn("WebsiteId")
                .ChildKeyColumn("CurrencyId")
                .Table("config.CurrenciesToWebsites");


        }
    }
}
